package com.zl.learning.object;

import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.List;

public class Test1 {
    static class B {
        public void say() {
            System.out.println("B say");
        }

        public B() {
        }

        public B(String name, String id, String age) {
            System.out.println(name + "-" + id + "-" + age);
        }
    }

    static class A extends B {
        @Override
        public void say() {
            System.out.println("A say");
        }

        public A() {
        }

        public A(String name, String id, String age) {
            super(name, id, age);
        }
    }

    static class Test {
        public static <T extends B> void say(List<T> t) {
            t.forEach(B::say);
            try {
                T t1 = t.get(0);
                T t2 = (T) t1.getClass().getConstructor(String.class, String.class, String.class).newInstance("zhansan", "33", "lils");
                t2.say();
            } catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
                e.printStackTrace();
            }
        }

        public static void main(String[] args) {
            B b = new B();
            A a = new A();
            say(Arrays.asList(a));
            say(Arrays.asList(b));
        }
    }
}
